package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.TsLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.album.AlbumTrackListVo;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"all"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	/**
	 * 判断用户是否购买过专辑
	 * @param albumId
	 * @return
	 */
	@TsLogin
	@Operation(summary = "判断用户是否购买过专辑")
	@GetMapping("/isPaidAlbum/{albumId}")
	public Result<Boolean> isPaidAlbum(@PathVariable("albumId") Long albumId){
		//  获取用户Id
		Long userId = AuthContextHolder.getUserId();
		//  调用服务层方法;
		Boolean flag = userInfoService.isPaidAlbum(userId, albumId);
		//  返回数据：
		return Result.ok(flag);
	}
	/**
	 * 判断用户是否购买声音列表
	 * @param albumId
	 * @param trackIdList
	 * @return
	 */
	@TsLogin
	@Operation(summary = "判断用户是否购买声音列表")
	@PostMapping("/userIsPaidTrack/{albumId}")
	public Result<Map<Long, Integer>> userIsPaidTrack(@PathVariable("albumId") Long albumId, @RequestBody List<Long> trackIdList){
		//  获取用户Id
		Long userId = AuthContextHolder.getUserId();
		//  调用服务层方法;
		Map<Long,Integer> map = userInfoService.userIsPaidTrack(albumId, trackIdList,userId);
		//  返回数据
		return Result.ok(map);
	}


	/**
	 * 根据userId 获取到用户信息
	 *
	 * @param userId
	 * @return
	 */
	@Operation(summary = "根据userId 获取到用户信息")
	@GetMapping("/getUserInfoVo/{userId}")
	public Result<UserInfoVo> getUserInfoVo(@PathVariable Long userId) {
		return Result.ok(userInfoService.getUserInfo(userId));
	}

	/**
	 * 获取到当前用户购买的声音id列表
	 * @param albumId
	 * @return
	 */
	@TsLogin
	@Operation(summary = "获取到当前用户购买的声音id列表")
	@GetMapping("/findUserPaidTrackList/{albumId}")
	public Result<List<Long>> findUserPaidTrackList(@PathVariable Long albumId){
		// 获取用户id
		Long userId = AuthContextHolder.getUserId();
		// 调用服务方法
		List<Long> userPaidTrackIdList = userInfoService.findUserPaidTrackList(albumId,userId);
		// 返回对象
		return Result.ok(userPaidTrackIdList);
	}


}

